/**
 * Created with IntelliJ IDEA.
 * Description:实现克隆对象
 * User: LXW
 * Date: 2022-05-30
 * Time: 14:08
 */

import com.sun.xml.internal.ws.addressing.WsaActionUtil;

/**
 * 自定义类型想要克隆必须实现Cloneable接口
 */
class Money implements Cloneable{
    public int m;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public int age;
    Money money = new Money();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person p = (Person) super.clone();
        p.money = (Money) this.money.clone();
        return p;
    }
}
public class Test {
    private static final String userName = "admin";
    private static final String passWord = "123456";
    public static void main(String[] args) throws CloneNotSupportedException {
//        Person person1 = new Person();
//        Person person2 = (Person) person1.clone();
//        System.out.println(person1.age);
//        System.out.println(person1.money.m);
//        System.out.println("===============");
//        person2.age = 20;
//        person2.money.m = 100;
//        System.out.println(person2.age);
//        System.out.println(person2.money.m);
//        String str2 = new String("11");
//        str2.intern();
//        String str1 = "11";
//        System.out.println(str1 == str2);
        try {
            login("wrw","1234");
        } catch (UserException userException) {
            userException.printStackTrace();
        } catch (PasswordException passwordException) {
            passwordException.printStackTrace();
        }
    }
    public static void login(String userName, String passWord) throws UserException, PasswordException {
        if(!Test.userName.equals(userName)) {
            throw new UserException("用户名错误");
        }
        if(!Test.passWord.equals(passWord)) {
            throw new PasswordException("密码错误");
        }
    }
}
